exports.search_order = function (req, res) {

    //获取restful参数
    var restfulParams = req.routeInfo.restfulParams;
    var resultData = {};

    var urlParams = "";
    var o_type = restfulParams.o_type == undefined ? "" : "/o_type/" + restfulParams.o_type;
    var o_pay_status = restfulParams.o_pay_status == undefined ? "" : "/o_pay_status/" + restfulParams.o_pay_status;
    var o_is_refund = restfulParams.o_is_refund == undefined ? "" : "/o_is_refund/" + restfulParams.o_is_refund;
    var o_no = restfulParams.o_no == undefined ? "" : "/o_no/" + restfulParams.o_no;
    var or = restfulParams.or == undefined ? "" : "/or/" + restfulParams.or;
    var skip = restfulParams.skip == undefined ? 0 : restfulParams.skip;

    var limit = restfulParams.limit == undefined ? config.publicConfig.LIMIT : restfulParams.limit;
    urlParams = o_type + o_pay_status + o_is_refund + o_no + or;
    //任务流创建
    async.waterfall([

        function (cb) {

            R.SEND_HTTP(
                req,
                {
                    url: CORE_APIConfig.coreAPI.search_order + "/is_hide/0/o_uid/" + restfulParams.o_uid + urlParams + "/sort_order/o_create_time-desc/skip/" + skip + "/limit/" + limit,
                    method: 'POST',
                    data: {
                        fields: [
                            "o_id",
                            "o_oid", //机构id
                            "o_no",  //订单编号
                            "o_type", //订单的类型 0-机构活动 1-论坛活动 2-课程\r\n
                            "o_aoc_id", //关联活动或者课程ID
                            "o_old_price", //原价
                            "o_money", //原价
                            "o_custom",
                            "o_phone",
                            "o_new_price", //现价
                            "o_organization_name", //机构名称
                            "o_course_name", //课程或者活动名称
                            "o_course_pic", //课程或活动的图片
                            "is_hide", //是否隐藏 0-否 1-是
                            "o_activity_type",//如果为活动， 0-拼团 1-投票 2-砍价 3-H5海报 4-助力 5-促销活动 6-微传单
                            "o_pay_status",//订单支付状态 0-未支付 1-已支付 2-支付失败 3-已验证 4-已取消 5-退款中 6-已退款 7-已评价
                            "o_is_refund",  //是否为退款订单
                            "o_is_cashback",  //是否为返现订单 0否 1是
                            "o_wechat_pay",  //实付金额
                        ].join(",")
                    }
                },
                function (err, data) {

                    resultData.orderListData = data.data;

                    cb();
                }
            );

        },
        function (cb) {
            //创建添加任务

            var orderListData = resultData.orderListData;

            var tasks = [];
            //循环节点列表
            orderListData.forEach(function (item, i) {

                //创建每一个插入任务
                tasks.push(function (cb) {

                    R.SEND_HTTP(
                        req,
                        {
                            url: CORE_APIConfig.coreAPI.search_verification_code + "/cn_ono/" + item.o_no,
                            method: 'POST',
                            data: {
                                fields: ["cn_number"].join(",")
                            }

                        },
                        function (err, data) {
                            //判断是否有错误信息
                            if (err) {
                                return RES.response(res, false, data);
                            }
                            var verificationCodeData = data.data;

                            if(verificationCodeData.length>0){

                                item.verificationMessage = data.data[0].cn_number;

                            }else{

                                item.verificationMessage = 0;

                            }

                            cb();
                        }
                    );

                });
            });
            async.waterfall(tasks, cb);
        },

    ], function (err, result) {

        //返回最终拼接结果
        RES.response(res, true, resultData);

    });
}